<?php
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include 'includes/header.php';
my_header('Казина :: Jwakk');
?>
        <div class="line"></div>
        <div class="mainConteiner">
                
            <?php include 'includes'.DIRECTORY_SEPARATOR.'top.php'; ?>
            <div class="topDelimiter"></div>

            <div class="content">

                <table cellspacing="0" cellpadding="0" width="100%"><tr>

                        <td class="Mainmenu" valign="top">
                            <a href="index.php"><div class="manuB">Казина</div></a>
                            <a href="buyCasino.php"><div class="manuB">Купи казино</div></a>
                            <a href="yoursC.php"><div class="manuB">Твои казина</div></a>
                            <a href="fight.php"><div class="manuB">Сбий се</div></a>
                            <a href="work.php"><div class="manuB">Работа</div></a>
                            <a href="zalozi.php"><div class="manuB">Залози</div></a>
                            <a href="coffee.php"><div class="manuB">Градът</div></a>
                            <a href="profile.php?user=<?php echo $_SESSION['user_info']['user']; ?>"><div class="manuB">Профил</div></a>
                            <?php
								$mes_q = mysql_query('SELECT id FROM message WHERE `do`="'.$_SESSION['user_info']['user'].'" AND `read`="0"');
								$mes_n = mysql_num_rows($mes_q);
								echo '<a href="mail.php"><div class="manuOnB">Съобщения ['.$mes_n.']</div></a>';
							?>
                            <a href="index.php?logout"><div class="manuBLogOut">Изход</div></a>

                            <br/>
                            <a href="#"><img alt="Последвайте Jwakk в Facebook" src="img/facebook.png" /></a>
                            <a href="#"><img alt="Последвайте Jwakk в Twitter" src="img/twitter.png" /></a>
                            <a href="#"><img alt="Абонирайте се за RSS емисии" src="img/rss.png" /></a>
                        </td>

                        <td valign="top">
                            <div class="gameBorder">
                                <div class="TheGame">
                                    <div class="gameTitle">Съобщения</div>	

                                    <div style="display:none;" class="overLevel">Нямаш нужните способност за да отвориш казино, но можеш да го поръчаш бързо чрез смс <a href="#">ТУК</a></div>
                                    
                                    <br/>

                                   <?php
                                        if(!isset($_GET['read'])){
                                            if(isset($_GET['delete'])){
                                                $delete = (int)$_GET['delete'];
                                                $del_q = mysql_query('SELECT id FROM message WHERE id="'.$delete.'" AND do="'.$_SESSION['user_info']['user'].'"');
                                                if(mysql_num_rows($del_q)==1){
                                                    mysql_query('DELETE FROM message WHERE id="'.$delete.'" AND do="'.$_SESSION['user_info']['user'].'"');
                                                    echo '<meta http-equiv="refresh" content="0;url=message.php">';
                                                    exit;
                                                }
                                            }
                                            $me = $_SESSION['user_info']['user'];
                                            $message_q = mysql_query('SELECT id,title,ot,date FROM message WHERE do="'.$me.'" ORDER BY date DESC');
                                            while($m_f = mysql_fetch_assoc($message_q)){
                                                echo '<a href="message.php?&read='.$m_f['id'].'">'.$m_f['title'].'</a> &nbsp; <a href="message.php?&delete='.$m_f['id'].'">Изтрии</a><br />';
                                            } 
                                        }
                                        elseif(isset($_GET['read'])){
                                            $id = $_GET['read'];
                                            $proverka = mysql_query('SELECT id FROM message WHERE id="'.$id.'" AND do="'.$_SESSION['user_info']['user'].'"');
                                            if(mysql_num_rows($proverka)==1){
                                                $message_q = mysql_query('SELECT title,message,ot FROM message WHERE id="'.$id.'"');
                                                $message_f = mysql_fetch_assoc($message_q);
                                                echo 'Title: '.$message_f['title'].'<br />';
                                                echo 'Ot: '.$message_f['ot'].'<br />';
                                                echo 'Message: '.$message_f['message'].'<br />';
                                            }
                                            else{
                                                echo '<meta http-equiv="refresh" content="0;url=message.php">';
                                                exit;
                                            }
                                        }
                                   ?>

                                </div>
                            </div>
                            <div class="help"> <a href="#">Помощ</a> | <a href="#">FAQ</a> | <a href="#">Условия</a> | <a href="#">Facebook</a></div>
                        </td>

                    </tr></table>


                <div class="footer">
                    © JwakK.com · Всички права запазени · <a href="#">Условия за ползване</a>
                </div>
            </div>
        </div>

        <div class="bottom"></div>

    </body>
</html>